// component/mSearch/index.ts
Component({
  options: {
    multipleSlots: true
  },
  
  /**
   * 组件的属性列表
   */
  properties: {
  	placeholder: {
  		type: String,
  		value: ''
  	},
  	showTop: {
  		type: Boolean,
			value: true
  	},
  	showBottom: {
  		type: Boolean,
  		value: false
  	},
		showFilter: {
			type: Boolean,
			value: false
    },
    paging: {
      type: Object,
      value: {
        current: 1,
        pageSize: 20,
        total: 0
      }
    }
  },

  /**
   * 组件的初始数据
   */
  data: {
		refre: false,
		
		filter: {
			show: false
		}
  },

  /**
   * 组件的方法列表
   */
  methods: {
		// 搜索第一页
		handleScrollTop() {
			this.setData({
				refre: true
			})
			this.triggerEvent('search', {
				current: 1
			});
		},
		
		// 滚动到底部
		handleScrollBottom() {
			let paging = this.this.properties.paging;
			if((paging.current+1) * this.paging.pageSize > paging.total) {
				return;
			}
			this.triggerEvent('search', {
				current: paging.current+1
			});
    },

    // 确认
    handleOk(event:any) {
      this.triggerEvent('search', {
				current: 1
      });
      if(event.currentTarget.dataset.close) {
      	this.toggleFilter();
      }
    },
    
    // 重置
    reset() {
      this.triggerEvent('reset');
    },
		
		// 关闭下拉刷新
		closePullDown() {
			this.setData({
				refre: false
			})
		},
		
		
		// 关闭筛选
		toggleFilter() {
			let filter = this.data.filter;
			filter.show = !filter.show;
			this.setData({
        filter
			})
		}
  }
})
